<?php
namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use App\Models\Pdf\TextbookRead;

class TextBookReadDataSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        try {
            $textbook_reads = DB::connection('zjmysql')->table('textbook_reads')->get()->toArray();
            $textbook_reads = json_decode(json_encode($textbook_reads), true);

            foreach ($textbook_reads as $textbook_read) {
                TextbookRead::query()->updateOrCreate(['id' => $textbook_read['id']], $textbook_read);
            }

            $this->command->info('教材点读数据填充完成！');
        } catch (\Exception $e) {
            $this->command->error('教材点读数据填充失败: ' . $e->getMessage());
            $this->command->warn('请检查 zjmysql 数据库连接配置是否正确');
        }
    }
}
